﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Markup;
using Buddy.Coroutines;
using log4net;
using Triton.Bot.Settings;
using Triton.Common;
using Triton.Common.LogUtilities;
using Triton.Game;
using Triton.Game.Abstraction;
using Triton.Game.Data;
using Triton.Game.Mapping;
using Triton.Bot;
using Logger = Triton.Common.LogUtilities.Logger;



public class RuntimeCode
{
	private static readonly ILog ilog_0 = Logger.GetLoggerInstanceForType();

	public void Execute()
	{
		using (TritonHs.AcquireFrame())
		{
			ilog_0.DebugFormat("[TClass]");
			//Vector3 v = new Vector3(28.541f, -6.460724f, -22.14572f);
			//Client.LeftClickAt(playButton.Transform.Position);//bald
			//Client.LeftClickAt(v);
			//TavernBrawlManager.Get().StartGame(0L);
			ilog_0.DebugFormat("[TClass] {0}", HeroPickerDisplay.Get() != null);
			//OnPlayButtonExecute1();
			//TavernBrawlDisplay tavernBrawlDisplay = TavernBrawlDisplay.Get();
			//tavernBrawlDisplay.OnPlayButtonExecute();
			//tavernBrawlDisplay.StartDungeonRun();
			
			ilog_0.DebugFormat("GuestHeroPickerDisplay.Get(){0}.HeroPickerDisplay.Get(){1}","unknown", HeroPickerDisplay.Get() != null);

			Task.Run(() => {
				HeroPickerDisplay heroPickerDisplay = HeroPickerDisplay.Get();
				DeckPickerTrayDisplay deckPickerTrayDisplay = heroPickerDisplay.m_deckPickerTray;
				deckPickerTrayDisplay.SetPlayButtonText("ggg");
				List<HeroPickerButton> heroButtons = deckPickerTrayDisplay.m_heroButtons;
				Client.LeftClickAt(heroButtons[1].Transform.Position);
				//Client.LeftClickAt(deckPickerTrayDisplay.m_backButton.Transform.Position);
			});





			//PlayButton playbutton= deckPickerTrayDisplay.m_playButton;
			//playbutton.OnPress();
			
			//UberText newPlayButtonText = playbutton.m_newPlayButtonText;
			//Renderer renderer = newPlayButtonText.m_TextMeshGameObject.Renderer;
			//Client.LeftClickAt(renderer.Bounds.m_Center);
			//Client.LeftClickAt(newPlayButtonText.Transform.Position);

			//Client.LeftClickAt(playbutton.Transform.Position);
			//ilog_0.DebugFormat("GuestHeroPickerDisplay.Get(){0}}", HeroPickerDisplay.Get());
			//TavernBrawlDisplay this1 = TavernBrawlDisplay.Get();
			//ilog_0.DebugFormat("{0}", TavernBrawlDisplay.Get().m_currentMission.IsDungeonRun);
			//ilog_0.DebugFormat("{0}", TavernBrawlManager.Get().SelectHeroBeforeMission());
			//bool flag2 = HeroPickerDisplay.Get() != null;
			//ilog_0.DebugFormat("{0}", this1.m_currentMission.canCreateDeck);
			//CollectionDeck collectionDeck = TavernBrawlManager.Get().CurrentDeck();
			//TavernBrawlManager.Get().StartGame(collectionDeck.ID);
			//ilog_0.DebugFormat("{0}", FriendChallengeMgr.Get().IsChallengeTavernBrawl());
			ilog_0.DebugFormat("Hello World!");
			Log log=Log.Get();
			//a=log.m_logInfos;
			//a = log.GetEnabledLogNames();
			//ilog_0.DebugFormat("[TClass] {0}", Log.All.GetContent());
		}
	}

	private void OnPlayButtonExecute1()
	{
		TavernBrawlDisplay this1 = TavernBrawlDisplay.Get();
		if (this1.m_currentMission.IsDungeonRun)
		{
			this1.StartDungeonRun();
			ilog_0.DebugFormat("[TClass] this1.StartDungeonRun();");
		}
		else if (TavernBrawlManager.Get().SelectHeroBeforeMission())
		{
			ilog_0.DebugFormat("[TClass] TavernBrawlManager.Get().SelectHeroBeforeMission()");
			bool flag = false;
			bool flag2 =  HeroPickerDisplay.Get() != null;
			ilog_0.DebugFormat("[TClass] {0}", HeroPickerDisplay.Get());
			if (!flag2)
			{
				ilog_0.DebugFormat("[TClass] TavernBrawlManager.Get().SelectHeroBeforeMission()");

			}
			if (!flag)
			{
				ilog_0.DebugFormat("Failed to load hero picker.", Array.Empty<object>());
			}
			if (flag2)
			{
				ilog_0.DebugFormat("Attempting to load HeroPickerDisplay a second time!", Array.Empty<object>());
				return;
			}
		}
		else if (this1.m_currentMission.canCreateDeck)
		{
			ilog_0.DebugFormat("[TClass] this1.m_currentMission.canCreateDeck");
			if (!TavernBrawlManager.Get().HasValidDeckForCurrent())
			{
				ilog_0.DebugFormat("Attempting to start a Tavern Brawl game without having a valid deck!");
				return;
			}
			CollectionDeck collectionDeck = TavernBrawlManager.Get().CurrentDeck();
			if (FriendChallengeMgr.Get().IsChallengeTavernBrawl())
			{
				ilog_0.DebugFormat("FriendChallengeMgr.Get().IsChallengeTavernBrawl()");
				FriendChallengeMgr.Get().SelectDeck(collectionDeck.ID);
				FriendlyChallengeHelper.Get().StartChallengeOrWaitForOpponent("GLOBAL_FRIEND_CHALLENGE_TAVERN_BRAWL_OPPONENT_WAITING_READY", new AlertPopup.ResponseCallback(this1.OnFriendChallengeWaitingForOpponentDialogResponse));
			}
			else
			{
				ilog_0.DebugFormat("else111()");
				TavernBrawlManager.Get().StartGame(collectionDeck.ID);
			}
		}
		else if (FriendChallengeMgr.Get().IsChallengeTavernBrawl())
		{
			ilog_0.DebugFormat("[TClass] FriendChallengeMgr.Get().IsChallengeTavernBrawl()");
			FriendChallengeMgr.Get().SkipDeckSelection();
			FriendlyChallengeHelper.Get().StartChallengeOrWaitForOpponent("GLOBAL_FRIEND_CHALLENGE_TAVERN_BRAWL_OPPONENT_WAITING_READY", new AlertPopup.ResponseCallback(this1.OnFriendChallengeWaitingForOpponentDialogResponse));
		}
		else
		{
			ilog_0.DebugFormat("[TClass] else");
			TavernBrawlManager.Get().StartGame(0L);
		}
		this1.DisablePlayButton();
	}

}